home *** CD-ROM | disk | FTP | other *** search
/ Magnum One / Magnum One (Mid-American Digital) (Disc Manufacturing).iso / d3 / rettig.arc / TRSOURCE.EXE / LJUST.C < prev    next >
C/C++ Source or Header  |  1990-10-22  |  1KB  |  57 lines

  1. /*********
  2. *  LJUST.C
  3. *
  4. *  by Tom Rettig
  5. *
  6. * Placed in the public domain by Tom Rettig Associates, 10/22/1990.
  7. *
  8. *  Syntax: LJUST( <expC> )
  9. *  Return: <expC> with leading spaces moved to right end.
  10. *          Return string is same length as <expC>.
  11. *********/
  12.  
  13. #include "trlib.h"
  14.  
  15. TRTYPE ljust()
  16. {
  17.    char *instr, *ret;
  18.    int i, j, pos;
  19.    static char funcname[] = { "ljust" };
  20.    if ( PCOUNT==1 && ISCHAR(1) )
  21.    {
  22.       instr  = _parc(1);
  23.       ret    = _tr_allocmem( (unsigned)(_tr_strlen(instr)+1));
  24.  
  25.       if ( ret )
  26.       {
  27.          if ( instr[0]==SPACEC )
  28.          {
  29.             for ( j=0; instr[j]==SPACEC; j++ )
  30.                ;
  31.             pos = j;                      /* first char past spaces */
  32.  
  33.             /* fill return buffer with chars */
  34.             for ( i=0; instr[j]; i++, j++ )
  35.                ret[i] = instr[j];
  36.  
  37.             /* fill return buffer with spaces */
  38.             for ( j=0; j<pos; i++, j++ )
  39.                ret[i] = instr[j];
  40.  
  41.             ret[i] = NULLC;
  42.  
  43.             _retc( ret );
  44.          }
  45.          else            /* return unchanged if no leading spaces */
  46.             _retc( instr );
  47.  
  48.          _tr_freemem( ret,(unsigned)(_tr_strlen(instr)+1) );
  49.       }
  50.       else            /* return unchanged if no memory */
  51.          _retc( instr );
  52.    }
  53.    else
  54.       _retc( _tr_errmsgs(funcname,E_SYNTAX) );
  55. }
  56.  
  57.